﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;






namespace helloworld2
{
    class Road
    {

        int id;
        double length;
        private List<KeyValuePair<int, int>> field = new List<KeyValuePair<int, int>>();
        RoadContainer rc = RoadContainer.Instance;
        List<Object> connections = new List<Object>(); 
        

        public Road(int id, List<KeyValuePair<int, int>> field)
        {
            this.id = id;
            this.field = field;
            this.length = findLength();

            //Console.WriteLine("heeeer" + this.field.Count);

        }

        public int getId()
        {
            return this.id;
        }

        public List<KeyValuePair<int, int>> getField()
        {
            var newField = new List<KeyValuePair<int, int>>();
            foreach (KeyValuePair<int, int> kp in field)
            {
                newField.Add(kp);
            }
            return newField;
        }

        private double findLength()
        {
            KeyValuePair<int, int> start = this.field[0];
            KeyValuePair<int, int> end = this.field[field.Count-1];

            double a;
            double b;

            if (start.Value > end.Value)
            {
                a = start.Value - end.Value;
            }

            else
            {
                a = end.Value - start.Value;
            }

            if (start.Key > end.Key)
            {
                b = start.Key - end.Key;
            }

            else
            {
                b = end.Key - start.Key;
            }
            
            double result = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
            result = result * 1.2;

            return result;
        }

        public KeyValuePair<int, int> getIndexOfField(int i)
        {
            return this.field[i];
        }

        public void addConnection()
        {
        }

        public void printFromField()
        {
            Console.WriteLine("THIS IS FROM fields in road " + field.Count);
        }

    }
}
